package cn.com.huzo.repository.master.impl;

import cn.com.huzo.model.entities.master.MpsItemEntity;
import cn.com.huzo.repository.master.MpsItemRepository;
import huzofw.repository.impl.GenericRepositoryImpl;
import huzofw.repository.impl.MyBatisDaoUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Repository;

/**
 * 主产品计划项目数据访问对象。
 *
 * @author 吴旭
 */
@Repository("MpsItemRepository")
public class MpsItemRepositoryImpl extends GenericRepositoryImpl<MpsItemEntity, Long>
        implements MpsItemRepository {

    private final String namespace = "cn.com.huzo.repository.master.MpsItemRepository";

    /**
     * 构造函数,设置the entity to MspItemRepositoryImpl.class.
     */
    public MpsItemRepositoryImpl() {
        super(MpsItemEntity.class);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<MpsItemEntity> fetchAll() {
        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchAll"));
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<MpsItemEntity> fetchAllByUser(Long currentUserId) {
        Map<String, Object> criterion = new HashMap();
        criterion.put("UserId", currentUserId);

        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchAllByUser"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer batchInsert(List<MpsItemEntity> itemList) {
        return getSqlSession().insert(MyBatisDaoUtils.getMapperQueryId(
                namespace, "batchInsert"), itemList);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer batchUpdate(List<MpsItemEntity> itemList) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "batchUpdate"), itemList);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer delete(Long key) {
        return getSqlSession().delete(MyBatisDaoUtils.getMapperQueryId(
                namespace, "delete"), key);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer resetLinesOrder() {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "resetLinesOrder"), null);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer updateLinesOrder(List<MpsItemEntity> itemsList) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "updateLinesOrder"), itemsList);
    }
}
